<template>
  <el-dialog
    :title="form.id?'编辑':'新增'"
    :visible.sync="dialogVisible"
    :before-close="close"
    width="40%"
  >
    <el-form label-width="100px">
      <el-form-item label="重点人员姓名">
        <el-input v-model="form.name" size="mini" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="联系方式">
        <el-input v-model="form.contact" size="mini" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="住址">
        <el-input v-model="form.address" size="mini" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="责任人">
        <el-select v-model="form.responsiblePersonId" size="mini" placeholder="请选择">
          <el-option
            v-for="item in personList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="问题描述">
        <el-input v-model="form.problemDescription" type="textarea" :rows="3" size="mini" placeholder="请输入" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { add, edit, queryPersonList } from '@/api/cadreBusiness/keyPersonnel'
export default {
  data () {
    return {
      dialogVisible: false,
      form: {},
      personList: []
    }
  },
  methods: {
    open (row) {
      this.getPersonList()
      this.form = { ...row }
      this.dialogVisible = true
    },
    getPersonList () {
      queryPersonList().then((res) => {
        this.personList = res?.data || []
      })
    },
    confirm () {
      let submitForm = add
      if (this.form.id) {
        submitForm = edit
      }
      submitForm(this.form).then((res) => {
        this.$message.success('保存成功')
        this.$emit('getData')
        this.close()
      })
    },
    close () {
      this.form = {}
      this.dialogVisible = false
    }
  }
}
</script>
<style lang="scss" scoped>
  .titleStyle {
    font-weight: 600;
    height: 35px;
    line-height: 35px;
    padding-left: 10px;
    padding-right: 10px;
    margin-bottom: 8px;
    background-color: #d8eff9;
    display: flex;
    justify-content: space-between;
  }
  .upload-demo {
    display: inline-block !important;
    margin-left: 16px;
  }
</style>
